package com.tsingteng.cosfun.ui.cosfun.presenter;

import com.tsingteng.cosfun.bean.AttentRecommendbean;
import com.tsingteng.cosfun.bean.BaseDataBean;
import com.tsingteng.cosfun.bean.BlindResp;
import com.tsingteng.cosfun.bean.CommBackBean;
import com.tsingteng.cosfun.bean.FollowBean;
import com.tsingteng.cosfun.bean.FoundAtBean;
import com.tsingteng.cosfun.bean.HomeBean;
import com.tsingteng.cosfun.bean.JoinCostarBean;
import com.tsingteng.cosfun.bean.OpusBean;
import com.tsingteng.cosfun.bean.RecommenResp;
import com.tsingteng.cosfun.bean.SearchResp;
import com.tsingteng.cosfun.bean.VidePersonBean;
import com.tsingteng.cosfun.callback.RxObserver;
import com.tsingteng.cosfun.common.Config;
import com.tsingteng.cosfun.mvp.presenter.BasePresenter;
import com.tsingteng.cosfun.ui.cosfun.contract.OpusContract;
import com.tsingteng.cosfun.ui.cosfun.imodel.OpusModel;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class OpusPresenter extends BasePresenter<OpusContract.IOpusView> implements OpusContract.IOpusPresenter {
    OpusModel opusModel = null;
    OpusContract.IOpusView iOpusView = null;

    public OpusPresenter() {
        this.opusModel = new OpusModel();
    }

    @Override
    public void getOpusList(String page_no) {
        iOpusView = getView();
        RxObserver<HomeBean> rxObserver = new RxObserver<HomeBean>(this) {
            @Override
            protected void onFaile(int errorCode, String errorMsg) {
                iOpusView.showFail(errorMsg);
            }

            @Override
            protected void onSuccess(HomeBean userBean) {
                iOpusView.showLogonResult(userBean.getVideoInfoList());
            }
        };
        opusModel.getOpusList(page_no, Config.PAGE_SIZE + "", System.currentTimeMillis() + "", "", rxObserver);
        addDisposable(rxObserver);
    }

    /**
     * 关注某人
     *
     * @param follow_id
     */
    @Override
    public void loginFollowFans(String follow_id) {
        iOpusView = getView();
        Callback<BaseDataBean<FollowBean>> rxObserver = new Callback<BaseDataBean<FollowBean>>() {
            @Override
            public void onResponse(Call<BaseDataBean<FollowBean>> call, Response<BaseDataBean<FollowBean>> response) {
                iOpusView.getFollowResult(response.body().data);
            }

            @Override
            public void onFailure(Call<BaseDataBean<FollowBean>> call, Throwable t) {

            }


        };

        opusModel.getFollowNotification(follow_id, rxObserver);
    }

    @Override
    public void grade(String video_id, long timestamp, int video_time) {
        iOpusView = getView();
        Callback<BaseDataBean<String>> rxObserver = new Callback<BaseDataBean<String>>() {
            @Override
            public void onResponse(Call<BaseDataBean<String>> call, Response<BaseDataBean<String>> response) {
            }

            @Override
            public void onFailure(Call<BaseDataBean<String>> call, Throwable t) {

            }


        };

        opusModel.getGrade(video_id, timestamp, video_time, rxObserver);
    }

    @Override
    public void del(String video_id) {
        iOpusView = getView();
        Callback<BaseDataBean<String>> rxObserver = new Callback<BaseDataBean<String>>() {
            @Override
            public void onResponse(Call<BaseDataBean<String>> call, Response<BaseDataBean<String>> response) {
            }

            @Override
            public void onFailure(Call<BaseDataBean<String>> call, Throwable t) {

            }


        };

        opusModel.getDel(video_id, rxObserver);
    }

    @Override
    public void getActivityVideoList(int activityId, String sortType, int page_no, int page_size) {
        iOpusView = getView();
        RxObserver<FoundAtBean> rxObserver = new RxObserver<FoundAtBean>(this) {
            @Override
            protected void onFaile(int errorCode, String errorMsg) {
                iOpusView.showFail(errorMsg);
            }

            @Override
            protected void onSuccess(FoundAtBean userBean) {
                iOpusView.showFound(userBean);
            }
        };
        opusModel.getVList(activityId,sortType,page_no,page_size,rxObserver);
        addDisposable(rxObserver);
    }

    @Override
    public void getBlindPhone() {
        iOpusView = getView();
        RxObserver<BlindResp> rxObserver = new RxObserver<BlindResp>(this) {
            @Override
            protected void onFaile(int errorCode, String errorMsg) {
                iOpusView.showFail(errorMsg);
            }

            @Override
            protected void onSuccess(BlindResp userBean) {
                iOpusView.showState(userBean);
            }
        };
        opusModel.getCheckBlind(rxObserver);
        addDisposable(rxObserver);
    }

    @Override
    public void getJoin(long video_id) {
        iOpusView = getView();
        RxObserver<BlindResp> rxObserver = new RxObserver<BlindResp>(this) {
            @Override
            protected void onFaile(int errorCode, String errorMsg) {
                iOpusView.showFail(errorMsg);
            }

            @Override
            protected void onSuccess(BlindResp userBean) {
                iOpusView.showJoinAdd(userBean);
            }
        };
        opusModel.getAddJoin(video_id,rxObserver);
        addDisposable(rxObserver);
    }


    //关注
    @Override
    public void getOpusAttention(String workId, String c, String deviceId, String type) {
        iOpusView = getView();
        RxObserver<BaseDataBean<String>> rxObserver = new RxObserver<BaseDataBean<String>>(this) {
            @Override
            protected void onFaile(int errorCode, String errorMsg) {
                iOpusView.showFail(errorMsg);
            }

            @Override
            protected void onSuccess(BaseDataBean<String> stringBaseDataBean) {

            }

        };
        opusModel.getOpusAttention(workId, c, deviceId, type, rxObserver);
        addDisposable(rxObserver);
    }

    //关注列表
    @Override
    public void getOpusAttentionList(String page_no, String page_size, String deviceId, String c) {
        iOpusView = getView();
        RxObserver<BaseDataBean<String>> rxObserver = new RxObserver<BaseDataBean<String>>(this) {
            @Override
            protected void onFaile(int errorCode, String errorMsg) {
                iOpusView.showFail(errorMsg);
            }

            @Override
            protected void onSuccess(BaseDataBean<String> stringBaseDataBean) {

            }

        };
        opusModel.getOpusAttentionList(page_no, page_size, deviceId, c, rxObserver);
        addDisposable(rxObserver);
    }


    //视频点赞
    @Override

    public void getOpusZan(String workId, String c, String deviceId, String type) {
        iOpusView = getView();
        RxObserver<CommBackBean> rxObserver = new RxObserver<CommBackBean>(this) {
            @Override
            protected void onFaile(int errorCode, String errorMsg) {
                iOpusView.showFail(errorMsg);
            }

            @Override
            protected void onSuccess(CommBackBean stringBaseDataBean) {
                iOpusView.showSendResult(0);
            }
        };
        opusModel.getOpusZan(workId, c, deviceId, type, rxObserver);
        addDisposable(rxObserver);
    }

    //评论点赞
    @Override
    public void getCommZan(String workId, String c, String deviceId, String type) {
        iOpusView = getView();
        RxObserver<BaseDataBean<String>> rxObserver = new RxObserver<BaseDataBean<String>>(this) {
            @Override
            protected void onFaile(int errorCode, String errorMsg) {
                iOpusView.showFail(errorMsg);
            }

            @Override
            protected void onSuccess(BaseDataBean<String> stringBaseDataBean) {
                iOpusView.showSendResult(1);
            }
        };
        opusModel.getCommmZan(workId, c, deviceId, type, rxObserver);
        addDisposable(rxObserver);
    }

    //不感兴趣
    @Override
    public void getLoseInterest(String workId, String timestamp) {
        iOpusView = getView();
        RxObserver<CommBackBean> rxObserver = new RxObserver<CommBackBean>(this) {
            @Override
            protected void onFaile(int errorCode, String errorMsg) {
                iOpusView.showFail(errorMsg);
            }

            @Override
            protected void onSuccess(CommBackBean stringBaseDataBean) {
                iOpusView.showSendResult(2);
            }
        };
        opusModel.getLoseInterest(workId, timestamp, "1", rxObserver);
        addDisposable(rxObserver);
    }

    /**
     * 合演的视屏
     *
     * @param video_info_id
     */
    @Override
    public void getCostarVideoInfo(String video_info_id) {
        iOpusView = getView();
        RxObserver<JoinCostarBean> rxObserver = new RxObserver<JoinCostarBean>(this) {
            @Override
            protected void onFaile(int errorCode, String errorMsg) {
                iOpusView.showFail(errorMsg);
            }

            @Override
            protected void onSuccess(JoinCostarBean showCostarVideoResult) {
                iOpusView.showCostarVideoResult(showCostarVideoResult);
            }
        };
        opusModel.getCostarVideoInfo(video_info_id, rxObserver);
        addDisposable(rxObserver);
    }

    @Override
    public void getFocusOpusList(String page_no) {
        iOpusView = getView();
        RxObserver<HomeBean> rxObserver = new RxObserver<HomeBean>(this) {
            @Override
            protected void onFaile(int errorCode, String errorMsg) {
                iOpusView.showFail(errorMsg);
            }

            @Override
            protected void onSuccess(HomeBean userBean) {
                iOpusView.showLogonResult(userBean.getVideoInfoList());
            }
        };
        opusModel.getFoucsOpusList(page_no, Config.PAGE_SIZE + "", System.currentTimeMillis() + "", "", rxObserver);
        addDisposable(rxObserver);
    }

    @Override
    public void getVideoInfoData(String videoId) {
        iOpusView = getView();
        RxObserver<OpusBean> rxObserver = new RxObserver<OpusBean>(this) {
            @Override
            protected void onFaile(int errorCode, String errorMsg) {
                iOpusView.showFail(errorMsg);
            }

            @Override
            protected void onSuccess(OpusBean opusBean) {
                iOpusView.showVideoInfo(opusBean);
            }
        };

        opusModel.getVideoInfo(videoId,rxObserver);
        addDisposable(rxObserver);

    }

    @Override
    public void getXiPuVideoListList(String paragraph_id, String pageNo, String type) {
        iOpusView = getView();
        RxObserver<HomeBean.DataBean> rxObserver = new RxObserver<HomeBean.DataBean>(this) {
            @Override
            protected void onFaile(int errorCode, String errorMsg) {
                iOpusView.showFail(errorMsg);
            }

            @Override
            protected void onSuccess(HomeBean.DataBean dataBean) {
                iOpusView.showLogonResult(dataBean);
            }
        };
        opusModel.getXiPuVideoListList(paragraph_id, pageNo + "", type, rxObserver);
        addDisposable(rxObserver);
    }

    @Override
    public void getILikeVideoListList(long userId, String c, String showType, String page_no, String page_size, String deviceId) {
        iOpusView = getView();
        iOpusView.showLoading("");
        Callback<BaseDataBean<HomeBean.DataBean>> workCallback = new Callback<BaseDataBean<HomeBean.DataBean>>() {
            @Override
            public void onResponse(Call<BaseDataBean<HomeBean.DataBean>> call, Response<BaseDataBean<HomeBean.DataBean>> response) {
                iOpusView.hideLoading();
                iOpusView.shoWorkData(response.body().data);
            }

            @Override
            public void onFailure(Call<BaseDataBean<HomeBean.DataBean>> call, Throwable t) {
                iOpusView.hideLoading();
            }
        };
        opusModel.getWorkList(userId, c, showType, page_no, page_size, deviceId, workCallback);
    }
     //去关注
    @Override
    public void getFocusInfo() {
        iOpusView = getView();
        RxObserver<RecommenResp> rxObserver = new RxObserver<RecommenResp>(this) {
            @Override
            protected void onFaile(int errorCode, String errorMsg) {
            }

            @Override
            protected void onSuccess(RecommenResp attentRecommendbeans) {
                iOpusView.showFocusInfo(attentRecommendbeans);
            }

        };
        opusModel.getFocusListInfo(rxObserver);
    }

    @Override
    public void loginNoFollow(String follow_id, int position) {
        iOpusView = getView();
        RxObserver<FollowBean> rxObserver = new RxObserver<FollowBean>(this) {
            @Override
            protected void onFaile(int errorCode, String errorMsg) {

            }

            @Override
            protected void onSuccess(FollowBean followBean) {
                iOpusView.showNoFollowResult(followBean, position);
            }
        };

        opusModel.getNoFollowNotification(follow_id, rxObserver);
        addDisposable(rxObserver);
    }

    @Override
    public void checkAndRemmend(String video_Id, int operate) {
        iOpusView = getView();
        RxObserver<String> rxObserver = new RxObserver<String>(this) {
            @Override
            protected void onFaile(int errorCode, String errorMsg) {
                 iOpusView.showFail(errorMsg);
            }

            @Override
            protected void onSuccess(String bean) {
               iOpusView.showCheckAndRemmend();
            }
        };
        opusModel.postCheckAndRemmond(video_Id,operate,rxObserver);
        addDisposable(rxObserver);
    }

}
